using UnityEngine;

public class StarRankControl : MonoBehaviour
{
	public UILabel levelIndexLabel;

	public UISprite levelSlider;

	public UILabel levelNameLabel;

	public UILabel starsCountLabel;

	public void OnEnable()
	{
		UpdateDisplay();
		BehaviourSingleton<GGNotificationCenter>.instance.onMessage -= OnMessageDelegate;
		BehaviourSingleton<GGNotificationCenter>.instance.onMessage += OnMessageDelegate;
	}

	public void OnDisable()
	{
		BehaviourSingleton<GGNotificationCenter>.instance.onMessage -= OnMessageDelegate;
	}

	private void OnMessageDelegate(string message)
	{
		if ("MessageConflictResolved".Equals(message))
		{
			UpdateDisplay();
		}
	}

	private void UpdateDisplay()
	{
		LevelSystem.CurrentDefinedPointLevelInfo currentDefinedPointLevelInfo = LevelSystem.instance.CurrentPlayerLevel();
		levelIndexLabel.text = (currentDefinedPointLevelInfo.levelIndex + 1).ToString();
		levelSlider.fillAmount = currentDefinedPointLevelInfo.subProgress;
		levelNameLabel.text = currentDefinedPointLevelInfo.definedPoint.levelName;
		starsCountLabel.text = currentDefinedPointLevelInfo.totalCollectedStars + "/" + (currentDefinedPointLevelInfo.definedPoint.totalStars + currentDefinedPointLevelInfo.definedPoint.starsNeededToNextLevel);
	}
}
